package com.xiaoshuidi.cloud.module.member.controller.admin.user;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.controller.app.user.vo.*;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.user.MemberUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "租客APP - 用户个人中心")
@RestController
@RequestMapping(ApiConstants.NAME+"/user")
@Validated
public class UserController {
    @Resource
    private MemberUserService userService;

    @PostMapping("/create")
    @Operation(summary = "创建个人客户")
    public CommonResult<Boolean> create(@RequestBody AppUserInfoCreateVO vo) {
        userService.createUser(vo);
        return success(true);
    }
    @Operation(summary = "获取会员统计信息")
    @GetMapping("/member-statistics")
    public CommonResult<List<MemberUserStatisticsVO>> getMemberStatistics(){
        return CommonResult.success(userService.getMemberStatistics());
    }


    @Operation(summary = "获取会员分页列表")
    @PostMapping("/member-page")
    public CommonResult<PageResult<MemberVO>> getMemberPage(@RequestBody MemberPageReqVO memberPageReqVo){
        return CommonResult.success(userService.getMemberPage(memberPageReqVo));
    }

    @Operation(summary = "启用禁用会员账号")
    @PostMapping("/member-update-state")
    public CommonResult<Boolean> memberUpdateState(@RequestBody MemberUpdateStateVO memberUpdateStateVO){
        return CommonResult.success(userService.memberUpdateState(memberUpdateStateVO));
    }


    @GetMapping("/get-by-id/{id}")
    @Operation(summary = "获得基本信息")
    public CommonResult<AppUserInfoRespVO> getUserInfo(@PathVariable("id") Long id) {

        return success(userService.getUserInfoById(id));
    }

}
